# -*- coding: utf-8 -*-
import sys
import fastdtw
from scikits.audiolab import wavread
from scikits.talkbox.features import mfcc


def getfeature(x):
    data, fs, enc=wavread(x)
    temp=mfcc(data)[0]
    return temp               

def mydist(a, b):
    i_dist=0
    for i in range(0, len(a)):
        i_dist=i_dist+abs(a[i]-b[i])
    return i_dist/len(a)

def mydtw(a, b):
    temp=fastdtw.fastdtw(a, b, 1, mydist)[0]    
    return temp
        
def filedist(file1, file2):
    f1=getfeature(file1)
    f2=getfeature(file2)
    return mydtw(f1, f2) 
  
if __name__ == '__main__':         
    if(len(sys.argv)==1):                
        #对于所有输入文件，进行识别，并计算识别率    
        print '请输入文件名'
    elif(len(sys.argv)==2):
        print getfeature(sys.argv[1])
    else:
        print filedist(sys.argv[1], sys.argv[2])    